<?php

namespace app\modules\cruise\models;

use Yii;

/**
 * This is the model class for table "member".
 *
 * @property int $id
 * @property string $phone 电话
 * @property string $passwd 密码
 * @property string $name 姓名
 * @property int $role 角色
 * @property string $login_time 最后次登录时间
 * @property string $desc 描述
 * @property int $status 1正常  2禁用
 * @property int $user_id 管理员编号
 * @property string $created_at
 * @property string $updated_at
 */
class Member extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'member';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['phone'], 'required'],
            [['role', 'status', 'user_id'], 'integer'],
            [['login_time', 'created_at', 'updated_at','group_num'], 'safe'],
            [['phone', 'passwd', 'name'], 'string', 'max' => 64],
            [['desc'], 'string', 'max' => 522],
            [['phone'], 'unique'],
        ];
    }

    // 保存前处理
    public function beforeSave($insert) {//{{{
        if($insert){
            $this->created_at = date("Y-m-d H:i:s");
            $this->user_id    = Yii::$app->user->id;
        }

        if($this->group_num){
           $this->group_num = json_encode($this->group_num); 
        }
        return parent::beforeSave($insert);
    }    

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'phone' => '电话',
            'passwd' => '密码',
            'name' => '姓名',
            'role' => '角色',
            'login_time' => '最后登录时间',
            'group_num' => '团号',
            'desc' => '描述',
            'status' => '状态',
            'user_id' => 'User ID',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }
}
